﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BaseSet.Data;
using BaseSet.Logic;
using BaseSet.Entity;
using BaseSet.Framework;
using BaseSet.Entity.Common;
using BaseSet.Entity.Common.Text;
using BaseSet;
using System.Data;

namespace WebSite.UserSetting
{
    public partial class CareList : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                LoadContent();
            }
        }

        #region 加载内容
        private void LoadContent()
        {
            Users uinfo = UserBase.GetCurrentUser();
            FriendHelper fhelper = new FriendHelper();
            Criteria c = new Criteria();
            c.Add(CriteriaType.Equals, "UsersID", uinfo.ID);

            //List<Friend> flist = fhelper.QueryFriendBySearch(c, new Order[] { new Order("CreateDate", OrderMode.Desc) });
            DataTable dtFriendList = fhelper.QueryFriendBySearchToTable(c, new Order[] { new Order("CreateDate", OrderMode.Desc) }, 0, 0, null);
            dtFriendList.Columns.Add(new DataColumn("SmallHeadImage"));
            dtFriendList.Columns.Add(new DataColumn("BlogPVNum"));

            if (dtFriendList != null && dtFriendList.Rows.Count > 0)
            {
                foreach (DataRow dr in dtFriendList.Rows)
                {
                    string FriendUsersID = dr["FriendUsersID"] + "";
                    //查找该用户的头像和收视量
                    Users friendinfo = new Users();
                    UsersHelper uhelper = new UsersHelper();
                    friendinfo = uhelper.GetUsers(FriendUsersID);
                    dr["SmallHeadImage"] = friendinfo.SmallHeadImage;
                    dr["BlogPVNum"] = friendinfo.BlogPVNum;
                }
            }

            dlCareList.DataSource = dtFriendList;
            dlCareList.DataBind();
        }
        #endregion

        #region 列表事件
        protected void dlCareList_ItemCommand(object source, DataListCommandEventArgs e)
        {
            HiddenField hidID = (HiddenField)e.Item.FindControl("hidID");
            string id = hidID.Value;
            if (e.CommandName == "cancel")
            {
                Friend finfo = new Friend();
                FriendHelper fhelper = new FriendHelper();
                finfo = fhelper.GetFriend(id);
                fhelper.DeleteFriend(finfo);
                LoadContent();
            }
        }
        #endregion
    }
}